package com.Web.Service.Impl;

import com.Web.DAO.IStudentDAO;
import com.Web.DAO.Impl.StudentDAOImpl;
import com.Web.Person.Query.StudentQuery;
import com.Web.Person.Student;
import com.Web.Person.VO.StudentVO;
import com.Web.Service.IStudentService;
import com.Web.util.PageInfo;
import com.Web.util.PageResult;

import java.util.List;

public class StudentServiceImpl implements IStudentService {

    private IStudentDAO studentDAO = new StudentDAOImpl();

    @Override
    public PageResult selectByPage(StudentQuery studentQuery) {
        System.out.println("StudentServiceImpl.selectByPage");
        List<StudentVO> list = studentDAO.selectByPage(studentQuery);
        int totalCount = studentDAO.selectTotalCount(studentQuery);
        PageResult<StudentVO> pageResult = new PageResult<>(0, "", totalCount, list);
        return pageResult;
    }

    @Override
    public void deleteById(int id) {
        studentDAO.deleteById(id);
    }

    @Override
    public void add(Student student) {
        studentDAO.add(student);
    }

    @Override
    public StudentVO selectById(int id) {
        StudentVO studentVO = studentDAO.selectById(id);
        return studentVO;
    }

    @Override
    public void Update(Student student) {
        studentDAO.update(student);
    }

    @Override
    public List<Student> selectAll() {
        List<Student> list = studentDAO.selectAll();
        return list;
    }

    @Override
    public void deleteAll(String[] ids) {
        for (String id : ids) {
            studentDAO.deleteById(Integer.parseInt(id));
        }
    }
}
